package cn.thoughtworks.school.services;

import cn.thoughtworks.school.feign.UserCenterFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class UserCenterService {

  @Autowired
  private UserCenterFeign userCenterFeign;

  public Map getUserInfoById(Long userId) {
    return userCenterFeign.getUserById(userId);
  }

  public List<Map> getUsersByUsername(String username) {
    return userCenterFeign.getUserByUserNameOrEmail(username);
  }

  public List getUsersByIds(String ids) {
    if (ids.equals("")) {
      return new ArrayList();
    }
    return userCenterFeign.getUsersByIds(ids);
  }

  public Long getUserCurrentOrganizationId(Long id) {
    Map user = userCenterFeign.getUserById(id);
    return Long.valueOf(user.get("currentOrganizationId").toString());
  }
}
